package com.lc.lc3;

import java.util.*;

public class Main {

}


class Solution {
    public int lengthOfLongestSubstring(String s) {
        Set<Character> set = new HashSet<>();
        int n = s.length();
        int ans = 0;
        char[] ss = s.toCharArray();
        int left = 0, right = 0;
        for (; right < n; right ++) {
        	char c = ss[right];
        	while(set.contains(c)) {
        		set.remove(c);
        		left ++;
        	}
        	set.add(c);
        	ans = Math.max(ans, right - left + 1);
        }
        return ans;
    }
}